<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>分公司退货审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../res/layui-v2.5.6/css/layui.css" media="all">
    <script type="text/javascript" src="../../../res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="/ok-admin/js/permissionSetting.js"></script>
</head>
<body>
<input type="hidden" name="status" id="status">
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">

    <div class="demoTable">
        搜索关键字：
        <div class="layui-inline">
            <input class="layui-input" name="operator" id="operator" autocomplete="off" placeholder="请输入采购人">
        </div>
        时间：
        <div class="layui-input-inline">
            <input type="text" name="startTime" id="startTime" autocomplete="off" class="layui-input" placeholder="yyyy-MM-dd">
        </div>
        --
        <div class="layui-input-inline">
            <input type="text" name="endTime" id="endTime" autocomplete="off" class="layui-input" placeholder="yyyy-MM-dd">
        </div>
        <button class="layui-btn" data-type="reload" id="sousuo" onclick="seach(this)">搜索</button>
    </div>

</script>

<script type="text/html" id="barDemo2">
    <a class="layui-btn layui-btn-xs" lay-event="ImmPurchaseDeatis">查询订单详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="HqReview">查询审核详情</a>
</script>
<script type="text/html" id="salesReturn">
    {{# if(returnUser()){ }}
        {{# if(authorization("salesReturn:finance")){ }}
            {{# if(d.isva<70){ }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="openAudit('70')" lay-event="audit" >审核</a>
            {{# }else{ }}
                <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
            {{# } }}
        {{# }else{ }}
            <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
        {{# } }}
    {{# }else{ }}
        <button class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" disabled>审核</button>
    {{# } }}

</script>

<script type="text/javascript" src="../../../res/layui-v2.5.6/layui.js"></script>
<script>
    var openIndex = null;
    var table = null;
    var laydate = null;
    layui.use(['table', 'laydate'], function () {
        table = layui.table;
        laydate = layui.laydate;
        table.render({
            method:"POST",
            elem: '#test'
            , url: '/immPurchase/queryAll4'
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: false
            , title: '分公司采购计划单数据表'
            , cols: [[
                 {field: 'purchaseId', title: '采购单ID', fixed: 'left'},
                 {field: 'immName', title: '分公司名称',align:"center"}
                , {field: 'purchaseCount', title: '采购总数量',align:"center"}
                , {field: 'purchaseMoney', title: '采购总金额',align:"center"}
                , {field: 'operator', title: '采购人', align:"center"}
                , {field: 'purchaseTime', title: '采购时间', align:"center"}
                , {field: 'isva', title: '审核状态', width: 150,align:"center",templet:function(d){
                        if(d.isva == '10'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">未申请</p>';
                        } else if(d.isva == '20'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">已申请</p>';
                        }else if(d.isva == '30'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">分公司采购经理通过</p>';
                        }else if(d.isva == '31'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">分公司采购经理不通过</p>';
                        }else if(d.isva == '40'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">分公司总经理通过</p>';
                        }else if(d.isva == '41'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">分公司总经理不通过</p>';
                        }else if(d.isva == '50'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司销售经理通过</p>';
                        }else if(d.isva == '51'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">总公司销售经理不通过</p>';
                        }else if(d.isva == '60'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司总经理通过</p>';
                        }else if(d.isva == '61'){
                            return '<p class="layui-btn layui-btn-danger layui-btn-xs">总公司总经理不通过</p>';
                        }else if(d.isva == '80'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">已提交退货申请</p>';
                        }else if(d.isva == '81'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司通过</p>';
                        }else if(d.isva == '66'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">退货中</p>';
                        }else if(d.isva == '67'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">退货失败</p>';
                        }else if(d.isva == '65'){
                            return '<p class="layui-btn layui-btn-warm layui-btn-xs">总公司审核中</p>';
                        }
                    }}
                , {field: 'remark', title: '备注', align:"center"}
                , {fixed: 'right', title: '查询信息', width: 210, toolbar: '#barDemo2',align:"center"}
                , {fixed: 'right', title: '审核财务', width: 180, toolbar: '#salesReturn', align:"center"}
            ]]
            , page: true
            , id: 'test'
            ,where: {  //查询采购单状态为 提交退货申请(68)
                isva: "66"  //过滤已经经过的流程
            }
        });



        //日期时间选择器
        laydate.render({
            elem: '#startTime'
            ,trigger: 'click'
        });

        laydate.render({
            elem: '#endTime'
            ,trigger: 'click'
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'Increasedata':
                    openIndex = layer.open({
                        type: 2,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['85%', '85%'], //宽高
                        title: '增加',
                        maxmin: true, //开启最大化最小化按钮
                        content: 'immPurchase-edit_add.html',
                    });
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'audit') {
                console.info(data)
                var id = data.purchaseId;
                //将采购单id赋值
                $("#purchaseId").val(id);
                //获取所点击审核的人的权限
                let status = $("#status").val();
                console.info($("#status").val());
                openIndex = layui.layer.open({
                    type: 2,
                    area: ['55%', '60%'], //宽高
                    title: '审核信息',
                    shift:1,//弹出框动画效果
                    skin: 'layui-layer-molv',//样式
                    shadeClose:true,//点击也能遮罩层关闭
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    maxmin: true, //开启最大化最小化按钮
                    // content:  $("#popUpdateTest"),
                    content:`/ok-admin/pages/audit/auditForm.html?id=${id}&status=${status}&audit=salesReturnFinance`
                });
            }else if(obj.event === "ImmPurchaseDeatis"){
                var id = data.purchaseId;
                openIndex = layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['85%', '85%'], //宽高
                    title: '采购明细',
                    maxmin: true, //开启最大化最小化按钮
                    content: '/ok-admin/pages/immPurchase/immPurchaseDeatis.html?id=' + id,
                });
            }else if(obj.event === "HqReview"){
                var id = data.purchaseId;
                openIndex = layer.open({
                    type: 2,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['85%', '85%'], //宽高
                    title: '审核记录',
                    maxmin: true, //开启最大化最小化按钮
                    content: '/ok-admin/pages/audit/auditList.html?marketId='+id //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            }else if(obj.event === "ApplyImmediately"){
                var id = data.purchaseId;
                console.info(id);
                $.ajax({
                    url: '/immPurchase/updateReviewState',
                    data: {purchaseId:id},
                    dataType: 'json',
                    type: 'POST',
                    success: function (obj) {
                        if (obj.status == 20) {
                            layer.msg("申请成功");
                            table.reload('test');
                        }else{
                            layer.msg("操作失败");
                        }
                    },
                    error: function () {

                    }
                });
            }
        });
        //审核请求
        window.openAudit = function (status) {
            $("#status").val(status);
        }
    });


    //搜索
    function seach() {
        var operator = $("#operator").val();
        var startTime = $("#startTime").val();
        var endTime = $("#endTime").val();
        var reviewState = $("#reviewState").val();
        table.reload('test', {
            where: {
                operator: operator,
                startTime: startTime,
                endTime: endTime,
                reviewState: reviewState
            },
            page: {
                curr: 1//从第一页开始查询
            }
        });

        //日期时间选择器
        laydate.render({
            elem: '#startTime'
            ,trigger: 'click'
        });

        laydate.render({
            elem: '#endTime'
            ,trigger: 'click'
        });
    }


    function close(obj) {
        layer.close(openIndex);
    }

    /**
     * 关闭弹出层
     */
    function closeOpen(msg) {
        layer.close(openIndex);
        layer.msg(msg, {time: 1000}, function () {
            table.reload("test");//刷新表格
        })
    }
</script>
</body>
</html>